package com.zmn.mcc.cas.server.controller.cas;

import com.taobao.api.ApiException;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.mcc.business.interfaces.staff.dingtalk.DingTalkService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author liubodong
 * @version v1.0
 * @since 2021/3/2 16:58
 */
@RestController
@RequestMapping("/ding-callback")
public class DingTalkCallbackController {

    @Resource
    DingTalkService dingTalkService;

    @RequestMapping(value = "/get-user-id")
    public ResponseDTO<String> getUserId(@RequestParam("code")String code) throws ApiException {

        // 根据unionid获取userid
        String unionid = dingTalkService.getUnionIdBySnsToken(code);
        // 根据userId获取用户信息
        ResponseDTO<String> resp = dingTalkService.getUserIdByUnionId(unionid);
        return resp;
    }
}
